<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list .aui-list-item-media {
            width: 3rem;
        }
        .notes-add {
            position: fixed;
            left: 0.5rem;
            bottom: 0.5rem;
            width: 3rem;
            z-index: 99;
        }
        textarea {
            height: 10rem;
            background-color: #ffffff;
            padding: 0.5rem;
        }
        .photos img {
            display: block;
            width: 100%;
        }
        .add-photos > div {
            width: 100%;
            height:5.15rem;
            line-height: 5.15rem;
        }
        .add-photos > div .aui-iconfont {
            font-size: 2rem;
            color: #ccc;
        }
        .image-item {
            position: relative;
            height: 5.3rem;
            overflow: hidden;
            background-color: #f0f0f0;
        }
        .image-item img {
            display: block;
            margin: 0 auto;
            width: auto;
            height: 100%;
        }
        .image-item .delete-btn {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 28px;
            height: 28px;
            background-color: rgba(0,0,0,0.7);
            margin-left: -14px;
            margin-top: -14px;
            color: #ffffff;
            text-align: center;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <section class="aui-content-padded">
        <textarea id="daily_content_id"
         placeholder="在这里输入日报内容..."></textarea>
    </section>
    <p class="aui-text-center aui-margin-t-15">上传附件,最多上传一张图片</p>
    <section class="aui-content-padded">
        <div class="aui-row aui-row-padded" >
          <div id="img_id"></div>
          <!--<div class="aui-col-xs-4 image-item">
              <input type="hidden" >
              <img src="../image/demo1.png" class="notes-image">
              <div class="delete-btn">
                  <i class="aui-iconfont aui-icon-trash"></i>
              </div>
          </div>-->
          <div class="aui-col-xs-4 add-photos"  onclick="openActionsheet()">
              <div class="aui-border aui-text-center">
                  <i class="aui-iconfont aui-icon-plus"></i>
              </div>
          </div>
        </div>

    </section>
    <section class="aui-content">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item" onclick="openWin('daily_mail');">
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">收件人</div>
                </div>
            </li>
        </ul>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/aui-actionsheet.js" ></script>
<script type="text/javascript">
    apiready = function(){
        $("#daily_content_id").focus()
        api.parseTapmode();
    }
    var actionsheet = new auiActionsheet();
    //打开底部弹窗
    function openActionsheet(){
        actionsheet.init({
            frameBounces:true,//当前页面是否弹动，（主要针对安卓端）
            title:"选择图片",
            cancelTitle:'取消',
            //destructiveTitle:'红色警告按钮',
            buttons:['拍照','图库选择']
        },function(ret){
            if(ret){
                if(ret.buttonIndex=="1"){
                    getPic("camera");
                }else {
                    getPic("library");
                }
            }
        })
    }

    //选择图片
    function getPic(type){
        api.getPicture({
            sourceType: type,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            quality: 100,
            targetWidth: 300,
            targetHeight: 300,
            saveToPhotoAlbum: false
        }, function(ret, err) {
            if (ret) {
                var html = ''
                html+='<div class="aui-col-xs-4 image-item">'
                html+='<input type="hidden" >'
                html+='<img src='+ret.data+' class="notes-image">'
                html+='<div class="delete-btn">'
                html+='<i class="aui-iconfont aui-icon-trash"></i>'
                html+='</div>'
                html+='</div>';
                $("#img_id").append(html);
                var img_files = $api.getStorage("img_file");
                if(img_files == undefined){
                    $api.setStorage("img_file", ret.data);
                }else {
                    $api.setStorage("img_file", img_files+","+ret.data);
                }
                //user = $api.getStorage(key);
                //alert(JSON.stringify(ret.data));
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    function openWin(name) {
        api.openWin({
            name: name,
            url: name+'_win.html',
        });
    }

    function addDaily(){
        var daily_content = $('#daily_content_id').val();
        var img_file = $api.getStorage("img_file");
        var username = $api.getStorage('username');

        var view_user = $api.getStorage("dm_users");
        //执行AJAX
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '拼命发送中...',
            text: '不如喝茶去...',
            modal: false
        });

        api.ajax({
            url: ServeUrl + 'm=Daily&a=addDaily',
            method: 'post',
            cache : false,
                timeout : 30,
                dataType : 'json',
            data: {
                values: {
                    daily_content : daily_content,
                    view_user : view_user,
                    username : username,
                },
                files: {
                    file: img_file,
                }
            }
        },function(ret, err){
            api.hideProgress();
            $api.rmStorage("img_file");
            $api.rmStorage("dm_users");
            if (ret) {
                api.toast({
                    msg:ret.data.msg
                });
                //关闭指定window，若待关闭的window不在最上面，则无动画
                api.closeWin();
            }else{
                api.toast({
                    msg:'未知错误'
                });
            }

        });

    }






</script>

</html>
